/**
 * Created by gongxun on 17/1/18.
 */

var GsbdxRoundEndedEventgsbdx = function(){
    var that = new GameResponseBase();

    that.handle = function (binary, msgid) {
        that.loadMessage(binary, msgid);

        that.handleMsg(that.msg);
    };

    that.handleMsg = function(msg){
        that.msg = msg;

        //记录打了多少盘
        mo.gsbdxTable.mPlayGameCount++;

        //是否是断线重练收到的
        if (mo.gsbdxTableStatus.isReconnect){
            //结算界面
            mo.gsbdxTable.mGsbdxTableUILayer.mGsbdxTableEndLayer.setEndInfo(that.msg, 0);
        }else{
            //ui动画
            var hosetSeat = 0;
            var scores = [];
            for (var seat = 0; seat < 5; seat++){
                var logicSeat = mo.gsbdxTableStatus.getLogicForView(seat, that.msg.MySeat - 1);
                var seatUser = that.msg["SeatUser" + (logicSeat + 1)];

                if (seatUser != null){
                    if (seatUser.IsHost){
                        hosetSeat = seat;
                    }

                    var allfen = 0;
                    var ids = seatUser.LostWin.ItemTypes;
                    var nums = seatUser.LostWin.ItemNums;
                    allfen = mo.gameUserInfo.getItemNum(ids, nums, 0);
                    scores.push(allfen);
                }else{
                    scores.push(-9999);
                }
            }
            var delayTime = mo.gsbdxTable.mGsbdxTableUILayer.setScoreAnim(scores, hosetSeat);

            //翻开手牌
            for (var seat = 0; seat < 5; seat++){
                var logicSeat = mo.gsbdxTableStatus.getLogicForView(seat, that.msg.MySeat - 1);

                var seatUser = that.msg["SeatUser" + (logicSeat + 1)];
                if (seatUser == null){
                    var cardNums = [];
                    cardNums.push(that.msg.LeftCards[logicSeat * 2]);
                    cardNums.push(that.msg.LeftCards[logicSeat * 2 + 1]);
                    var cardType = mo.gsbdxTableStatus.getCardType(cardNums);

                    //牌
                    mo.gsbdxTable.mGsbdxTableCardLayer.setKaipaiSeat(seat, cardNums, false);
                    //ui动画
                    mo.gsbdxTable.mGsbdxTableUILayer.setKaipaiSeat(seat, cardType, false);
                }
            }

            //结算界面
            mo.gsbdxTable.mGsbdxTableUILayer.mGsbdxTableEndLayer.setEndInfo(that.msg, delayTime);
        }

    };

    return that;
};